package cn.talkimages.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.core.env.PropertyResolver;

import cn.talkimages.framework.action.ActionResults;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class WebBaseAction extends ActionSupport implements ActionResults,
		RawHttpServletAccess {

	private static final long serialVersionUID = 1388453020790609320L;

	private PropertyResolver sysPropertyConfig;

	/**
	 * 获得当前的ActionContext
	 * 
	 * @return ActionContext
	 */
	public ActionContext getActionContext() {
		return ActionContext.getContext();
	}

	// -------------- Http Servlet Support -------------- //

	public HttpServletRequest getHttpServletRequest() {
		return ServletActionContext.getRequest();
	}

	public HttpServletResponse getHttpServletResponse() {
		return ServletActionContext.getResponse();
	}

	public HttpSession getHttpSession() {
		return getHttpServletRequest().getSession();
	}

	// -------------- Configure File Access -------------- //

	public String getConfStrValue(String key) {
		return sysPropertyConfig.getProperty(key);
	}

	public Integer getConfIntValue(String key) {
		return sysPropertyConfig.getProperty(key, Integer.class);
	}

	public PropertyResolver getSysPropertyConfig() {
		return sysPropertyConfig;
	}

	public void setSysPropertyConfig(PropertyResolver sysPropertyConfig) {
		this.sysPropertyConfig = sysPropertyConfig;
	}
}
